<template>
    <div class="html-attr">
        <Codemirror ref="codemirror" mode="htmlmixed"></Codemirror>
        <div class="html-botton">
            <div class="botton" @click="clear">清 除</div>
            <div class="botton" @click="setData">确 定</div>
        </div>
    </div>
</template>

<script>
import store from '@/js/store/state.js';
import JQuery from 'jquery';
import history from '@/js/main/history.js';
import Codemirror from '@/view/component/Codemirror.vue';

export default {
    data() {
        return {
            JQuery: JQuery,
            history: history,
            store: store,
            currentElementList: store.getCurrentElementList()
        };
    },
    components: {
        Codemirror
    },
    mounted() {
        this.$nextTick(() => {
            if (this.currentElementList[0].data.html) {
                this.$refs.codemirror.setData(this.currentElementList[0].data.html);
            }
        });
    },
    methods: {
        clear() {
            this.$refs.codemirror.setData('');
            this.currentElementList[0].data.html = '';
            history.addHistory(store.clone(), 181);
        },
        setData() {
            this.currentElementList[0].data.html = this.$refs.codemirror.getData();
            history.addHistory(store.clone(), 182);
        }
    },
};
</script>

<style scoped lang="scss">
$background: #ffffff0f;
.html-attr {
    .html-botton {
        display: flex;
        line-height: 60px;
        flex-direction: row;
        justify-content: flex-end;
        .botton {
            width: 50%;
            height: 25px;
            line-height: 25px;
            background: $background;
            margin: 10px 20px;
            color: $FontWhite;
            text-align: center;
            cursor: pointer;
        }
    }
}
</style>